package net.sudot.chess.business.model;

import com.fasterxml.jackson.annotation.JsonFilter;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.sudot.chess.business.model.converter.AttributeConverter;

import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Transient;
import java.util.Map;

/**
 * 插件配置
 *
 * @author tangjialin on 2018-03-18.
 */
@Getter
@Setter
@Accessors(chain = true)
@JsonFilter("IgnoreBaseEntityProperties")
@Entity
public class PluginConfig extends BaseOrderedEntity<PluginConfig> {
    /** 插件的标识信息(插件的实现类在spring容器中的名称) */
    private String pluginId;
    /** 显示名称(客户看到的名称) */
    private String displayName;
    /** 启用 */
    private Boolean enabled;
    /** 属性 */
    @Convert(converter = AttributeConverter.class)
    private Map<String, String> attributes;

    /**
     * 获取属性值
     *
     * @param name 属性名称
     * @return 属性值
     */
    @Transient
    public String getAttribute(String name) {
        if (name == null || name.isEmpty()) {
            return null;
        }
        Map<String, String> attributes = getAttributes();
        return attributes == null ? null : attributes.get(name);
    }

}

